package com.cbank.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.cbank.domain.City;
@Repository
public interface CityDao {
	String ALL = "id,name,status,update_time,create_time";

	@Insert("insert into city(name,status) values(#{name},#{status})")
	@Options(useGeneratedKeys = true)
    void insert(City obj);
	
	@Select("select " + ALL + " from city where id = #{id} and status = 1 limit 1")
    City getById(Long id);

	@Select("select " + ALL + " from city where status = 1 order by create_time DESC limit #{index},#{offset}")
    List<City> getPage(@Param(value = "index") int index, @Param(value = "offset") int offset);
	
	@Select("select " + ALL + " from city where status = 1 order by create_time DESC limit #{index},#{offset}")
    List<City> getPageWithParam(@Param(value = "index") int index, @Param(value = "offset") int offset);
	
	@Select("select count(1) from city where status = 1")
    int getCount();
}
